<template>
  <div class="app-container">
    <div class="block" >
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageData.currentPage"
        :page-sizes="pagination.options"
        :page-size="pagination.size"
        layout="sizes, prev, pager, next"
        :total="pageData.total"
      >
      </el-pagination>
    </div>

    <el-table
      :data="pageData.items"
      style="width: 100%" v-loading="this.jobs.loading" empty-text="暂无数据">
      <el-table-column
        label="ID"
        prop="id"
        width="320"
      >
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="right">
            <p><img :src="scope.row.thumbnail" width="120" height="120"/></p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{scope.row.id}}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        label="名称"
        width="280"
        prop="fullTitle"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="观看人数"
        prop="viewCount"
        width="100"
        :formatter="numberFormatter"
      >
      </el-table-column>
      <el-table-column
        label="时长"
        prop="duration"
        width="100"
        :formatter="hourTimeFormatter"
      >
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"><a :href="scope.row.url" :download="scope.row.fullTitle+'.'+scope.row.ext">下载</a>
          </el-button>
          <el-button
            size="mini"><a target="_blank" :href="scope.row.webpageUrl">详情</a>
          </el-button>
          <!--<el-button-->
          <!--size="mini"-->
          <!--type="danger"-->
          <!--@click="handleDelete(scope.$index, scope.row)">删除-->
          <!--</el-button>-->
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { message, pagable, utils } from '@/mixins/'

  export default {
    mixins: [pagable, message, utils],
    data() {
      return {
        jobs: {
          loading: false
        }
      }
    },
    mounted() {
      this.getData()
    },
    methods: {
      getData() {
        this.$store.dispatch('getMediaList', {
          page: this.pageData.currentPage,
          pageSize: this.pagination.size
        }).then((data) => {
          this.pageData.items = data.items
        })
      }
    }
  }
</script>

<style scoped>
  .line {
    text-align: center;
  }
</style>

